package framework 
{
	/**
	 * 切换等级
	 * @author Henrylee{henrylee_sz@qq.com}
	 */
	public class LvManager 
	{
		static private var _instance: LvManager;
		
		/** 等级资源管理类的头名称 */
		static private const RAW_HEAD: String = "LvCanvas";
		
		/** 当前所处的等级 */
		private var _lv:int = -1;
		
		private var _lvCanvas: ILvCanvas;
		
		public function enterLevel(lv:int):Boolean
		{
			if (lv == _lv) return false;
			
			var Definition: Class = GlobalVar.lvCanvasList[lv];
			if (Definition != null)
			{
				removeCrt();
				
				_lv = lv;
				
				_lvCanvas = new Definition();
				_lvCanvas.active();
				
				return true;
			}
			else
			{
				return false;
			}
		}
		
		
		private function removeCrt():void
		{
			if (_lvCanvas != null)
			{
				_lvCanvas.disable();
				_lvCanvas = null;
			}
		}
		
		
		
		static public function get instance():LvManager
		{
			if (_instance == null)
				_instance = new LvManager();
			return _instance;
		}
		
		
		public function get lv():int { return _lv; }
		public function set lv(value:int):void { _lv = value; }
		
	}

}